package com.dlsy.ygj.util;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

public class SqlFilter implements FilenameFilter {

	public boolean isSql(String file) {
	    if (file.toLowerCase().endsWith(".zip")){
	      return true;
	    }else{
	      return false;
	    }
	}
	public boolean isSrorefront(String sroId){
		HttpServletRequest request = ServletActionContext.getRequest();
//		int storefront_id = 1;
		int storefront_id = Integer.parseInt(request.getSession().getAttribute("storefrontId").toString());
		String storefront = storefront_id+"_";
		if (sroId.startsWith(storefront)) {
			return true;
		} else {
			return false;
		}
	}
	public boolean accept(File dir,String fname){
		 return (isSql(fname)&&isSrorefront(fname));
	}
//	public static void main(String[] args) {
//		File directory=new File("d:\\");
//        String[] sqls = directory.list(new SqlFilter());
//        System.out.println("size="+sqls.length);
//        List<String> slist = new ArrayList<String>();
//        for (int i = 0; i < sqls.length; i++){
//        	System.out.println("sqlfile="+sqls[i]);
//        	slist.add(sqls[i]);
//        }
//	}
	
}
